﻿// Decompiled with JetBrains decompiler
// Type: Bannerlord.ModuleManager.ApplicationVersion
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;

#nullable enable
namespace Bannerlord.ModuleManager
{
  internal record ApplicationVersion() : IComparable<ApplicationVersion>
  {
    public static ApplicationVersion Empty { get; } = new ApplicationVersion();

    public ApplicationVersionType ApplicationVersionType { get; set; }

    public int Major { get; set; }

    public int Minor { get; set; }

    public int Revision { get; set; }

    public int ChangeSet { get; set; }

    public ApplicationVersion(
      ApplicationVersionType applicationVersionType,
      int major,
      int minor,
      int revision,
      int changeSet)
    {
      this.ApplicationVersionType = applicationVersionType;
      this.Major = major;
      this.Minor = minor;
      this.Revision = revision;
      this.ChangeSet = changeSet;
    }

    public bool IsSame(ApplicationVersion? other)
    {
      int major1 = this.Major;
      int? major2 = other?.Major;
      int valueOrDefault = major2.GetValueOrDefault();
      return major1 == valueOrDefault & major2.HasValue && this.Minor == other.Minor && this.Revision == other.Revision;
    }

    public bool IsSameWithChangeSet(ApplicationVersion? other)
    {
      int major1 = this.Major;
      int? major2 = other?.Major;
      int valueOrDefault = major2.GetValueOrDefault();
      return major1 == valueOrDefault & major2.HasValue && this.Minor == other.Minor && this.Revision == other.Revision && this.ChangeSet == other.ChangeSet;
    }

    public override string ToString()
    {
      return string.Format("{0}{1}.{2}.{3}.{4}", (object) ApplicationVersion.GetPrefix(this.ApplicationVersionType), (object) this.Major, (object) this.Minor, (object) this.Revision, (object) this.ChangeSet);
    }

    public int CompareTo(ApplicationVersion? other)
    {
      return ApplicationVersionComparer.CompareStandard(this, other);
    }

    public static bool operator <(ApplicationVersion left, ApplicationVersion right)
    {
      return left.CompareTo(right) < 0;
    }

    public static bool operator >(ApplicationVersion left, ApplicationVersion right)
    {
      return left.CompareTo(right) > 0;
    }

    public static bool operator <=(ApplicationVersion left, ApplicationVersion right)
    {
      return left.CompareTo(right) <= 0;
    }

    public static bool operator >=(ApplicationVersion left, ApplicationVersion right)
    {
      return left.CompareTo(right) >= 0;
    }

    public static char GetPrefix(ApplicationVersionType applicationVersionType)
    {
      if (true)
        ;
      char prefix;
      switch (applicationVersionType)
      {
        case ApplicationVersionType.Alpha:
          prefix = 'a';
          break;
        case ApplicationVersionType.Beta:
          prefix = 'b';
          break;
        case ApplicationVersionType.EarlyAccess:
          prefix = 'e';
          break;
        case ApplicationVersionType.Release:
          prefix = 'v';
          break;
        case ApplicationVersionType.Development:
          prefix = 'd';
          break;
        default:
          prefix = 'i';
          break;
      }
      if (true)
        ;
      return prefix;
    }

    public static ApplicationVersionType FromPrefix(char applicationVersionType)
    {
      if (true)
        ;
      ApplicationVersionType applicationVersionType1;
      switch (applicationVersionType)
      {
        case 'a':
          applicationVersionType1 = ApplicationVersionType.Alpha;
          break;
        case 'b':
          applicationVersionType1 = ApplicationVersionType.Beta;
          break;
        case 'd':
          applicationVersionType1 = ApplicationVersionType.Development;
          break;
        case 'e':
          applicationVersionType1 = ApplicationVersionType.EarlyAccess;
          break;
        case 'v':
          applicationVersionType1 = ApplicationVersionType.Release;
          break;
        default:
          applicationVersionType1 = ApplicationVersionType.Invalid;
          break;
      }
      if (true)
        ;
      return applicationVersionType1;
    }

    public static bool TryParse(string? versionAsString, out ApplicationVersion version)
    {
      return ApplicationVersion.TryParse(versionAsString, out version, true);
    }

    public static bool TryParse(string? versionAsString, out ApplicationVersion version, bool asMin)
    {
      int result1 = asMin ? 0 : int.MaxValue;
      int result2 = asMin ? 0 : int.MaxValue;
      int result3 = asMin ? 0 : int.MaxValue;
      int result4 = asMin ? 0 : int.MaxValue;
      bool flag = false;
      version = ApplicationVersion.Empty;
      if (versionAsString == null)
        return false;
      string[] strArray = versionAsString.Split('.');
      if (strArray.Length != 3 && strArray.Length != 4 && strArray[0].Length == 0)
        return false;
      ApplicationVersionType applicationVersionType = ApplicationVersion.FromPrefix(strArray[0][0]);
      if (!flag && !int.TryParse(strArray[0].Substring(1), out result1))
      {
        if (strArray[0].Substring(1) != "*")
          return false;
        result1 = int.MinValue;
        result2 = int.MinValue;
        result3 = int.MinValue;
        result4 = int.MinValue;
        flag = true;
      }
      if (!flag && !int.TryParse(strArray[1], out result2))
      {
        if (strArray[1] != "*")
          return false;
        result2 = asMin ? 0 : int.MaxValue;
        result3 = asMin ? 0 : int.MaxValue;
        result4 = asMin ? 0 : int.MaxValue;
        flag = true;
      }
      if (!flag && !int.TryParse(strArray[2], out result3))
      {
        if (strArray[2] != "*")
          return false;
        result3 = asMin ? 0 : int.MaxValue;
        result4 = asMin ? 0 : int.MaxValue;
        flag = true;
      }
      if (!flag && strArray.Length == 4 && !int.TryParse(strArray[3], out result4))
      {
        if (strArray[3] != "*")
          return false;
        result4 = asMin ? 0 : int.MaxValue;
      }
      version = new ApplicationVersion()
      {
        ApplicationVersionType = applicationVersionType,
        Major = result1,
        Minor = result2,
        Revision = result3,
        ChangeSet = result4
      };
      return true;
    }

    [CompilerGenerated]
    protected virtual bool PrintMembers(StringBuilder builder)
    {
      RuntimeHelpers.EnsureSufficientExecutionStack();
      builder.Append("ApplicationVersionType = ");
      builder.Append(this.ApplicationVersionType.ToString());
      builder.Append(", Major = ");
      builder.Append(this.Major.ToString());
      builder.Append(", Minor = ");
      builder.Append(this.Minor.ToString());
      builder.Append(", Revision = ");
      builder.Append(this.Revision.ToString());
      builder.Append(", ChangeSet = ");
      builder.Append(this.ChangeSet.ToString());
      return true;
    }

    [CompilerGenerated]
    public override int GetHashCode()
    {
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      return ((((EqualityComparer<Type>.Default.GetHashCode(this.EqualityContract) * -1521134295 + EqualityComparer<ApplicationVersionType>.Default.GetHashCode(this.\u003CApplicationVersionType\u003Ek__BackingField)) * -1521134295 + EqualityComparer<int>.Default.GetHashCode(this.\u003CMajor\u003Ek__BackingField)) * -1521134295 + EqualityComparer<int>.Default.GetHashCode(this.\u003CMinor\u003Ek__BackingField)) * -1521134295 + EqualityComparer<int>.Default.GetHashCode(this.\u003CRevision\u003Ek__BackingField)) * -1521134295 + EqualityComparer<int>.Default.GetHashCode(this.\u003CChangeSet\u003Ek__BackingField);
    }

    [CompilerGenerated]
    public virtual bool Equals(ApplicationVersion? other)
    {
      if ((object) this == (object) other)
        return true;
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      return (object) other != null && this.EqualityContract == other.EqualityContract && EqualityComparer<ApplicationVersionType>.Default.Equals(this.\u003CApplicationVersionType\u003Ek__BackingField, other.\u003CApplicationVersionType\u003Ek__BackingField) && EqualityComparer<int>.Default.Equals(this.\u003CMajor\u003Ek__BackingField, other.\u003CMajor\u003Ek__BackingField) && EqualityComparer<int>.Default.Equals(this.\u003CMinor\u003Ek__BackingField, other.\u003CMinor\u003Ek__BackingField) && EqualityComparer<int>.Default.Equals(this.\u003CRevision\u003Ek__BackingField, other.\u003CRevision\u003Ek__BackingField) && EqualityComparer<int>.Default.Equals(this.\u003CChangeSet\u003Ek__BackingField, other.\u003CChangeSet\u003Ek__BackingField);
    }

    [CompilerGenerated]
    protected ApplicationVersion(ApplicationVersion original)
    {
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      this.\u003CApplicationVersionType\u003Ek__BackingField = original.\u003CApplicationVersionType\u003Ek__BackingField;
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      this.\u003CMajor\u003Ek__BackingField = original.\u003CMajor\u003Ek__BackingField;
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      this.\u003CMinor\u003Ek__BackingField = original.\u003CMinor\u003Ek__BackingField;
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      this.\u003CRevision\u003Ek__BackingField = original.\u003CRevision\u003Ek__BackingField;
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      this.\u003CChangeSet\u003Ek__BackingField = original.\u003CChangeSet\u003Ek__BackingField;
    }
  }
}
